package com.ruoyi.business.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.JtPaymentOrder;
import com.ruoyi.business.service.IJtPaymentOrderService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 支付单Controller
 * 
 * @author Alan Zhang
 * @date 2025-03-29
 */
@Controller
@RequestMapping("/business/payment")
public class JtPaymentOrderController extends BaseController
{
    private String prefix = "business/payment";

    @Autowired
    private IJtPaymentOrderService jtPaymentOrderService;

    @RequiresPermissions("business:payment:view")
    @GetMapping()
    public String payment()
    {
        return prefix + "/payment";
    }

    /**
     * 查询支付单列表
     */
    @RequiresPermissions("business:payment:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JtPaymentOrder jtPaymentOrder)
    {
        startPage();
        List<JtPaymentOrder> list = jtPaymentOrderService.selectJtPaymentOrderList(jtPaymentOrder);
        return getDataTable(list);
    }

    /**
     * 导出支付单列表
     */
    @RequiresPermissions("business:payment:export")
    @Log(title = "支付单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JtPaymentOrder jtPaymentOrder)
    {
        List<JtPaymentOrder> list = jtPaymentOrderService.selectJtPaymentOrderList(jtPaymentOrder);
        ExcelUtil<JtPaymentOrder> util = new ExcelUtil<JtPaymentOrder>(JtPaymentOrder.class);
        return util.exportExcel(list, "支付单数据");
    }

    /**
     * 新增支付单
     */
    @RequiresPermissions("business:payment:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存支付单
     */
    @RequiresPermissions("business:payment:add")
    @Log(title = "支付单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JtPaymentOrder jtPaymentOrder)
    {
        return toAjax(jtPaymentOrderService.insertJtPaymentOrder(jtPaymentOrder));
    }

    /**
     * 修改支付单
     */
    @RequiresPermissions("business:payment:edit")
    @GetMapping("/edit/{paymentId}")
    public String edit(@PathVariable("paymentId") Long paymentId, ModelMap mmap)
    {
        JtPaymentOrder jtPaymentOrder = jtPaymentOrderService.selectJtPaymentOrderByPaymentId(paymentId);
        mmap.put("jtPaymentOrder", jtPaymentOrder);
        return prefix + "/edit";
    }

    /**
     * 修改保存支付单
     */
    @RequiresPermissions("business:payment:edit")
    @Log(title = "支付单", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JtPaymentOrder jtPaymentOrder)
    {
        return toAjax(jtPaymentOrderService.updateJtPaymentOrder(jtPaymentOrder));
    }

    /**
     * 删除支付单
     */
    @RequiresPermissions("business:payment:remove")
    @Log(title = "支付单", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jtPaymentOrderService.deleteJtPaymentOrderByPaymentIds(ids));
    }
}
